package com.heima.file.config;

import com.heima.file.service.FileStorageService;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ybw
 * @version 1.0
 * @date 2021/12/12 14:53
 */
@Data
@Configuration
@EnableConfigurationProperties({MinioConfigProperties.class})
@ConditionalOnClass(FileStorageService.class)
public class MinioConfig {
  @Autowired private MinioConfigProperties minIOConfigProperties;

  @Bean
  public MinioClient buildMinioClient() {
    return MinioClient.builder()
        .credentials(minIOConfigProperties.getAccessKey(), minIOConfigProperties.getSecretKey())
        .endpoint(minIOConfigProperties.getEndpoint())
        .build();
  }
}
